<template>
	<view class='container' >
		<view class="wrapper">
			<view class='mui-content input-content'>
				<view class='input-item'>
					<text class="tit">姓名</text>
					<input class='minput' type='text' v-model="name" placeholder='联系人姓名'></input>
				</view>
				<view class='input-item'>
					<text class="tit">手机</text>
					<input class='minput' type='number' v-model="tel" placeholder='请输入联系方式'></input>
				</view>
				<view id='showCityPicker3' class='input-item' @click="open">
					<text class="tit">地址</text>
					<input class='minput' v-model="addr_text" placeholder="请选择所属区域" disabled="ture"></input>
					<!-- <text class="iconfont icon-fanhui1"></text> -->
				</view>
				<view class='input-item'>
					<textarea class="xiangxi" v-model="detail" placeholder="请输入详细地址" placeholder-style="color:#999;"  />
					</view>
				<view class="moren">
						<view class="uni-list">
							<view class="uni-list-cell uni-list-cell-pd">
								<view class="uni-list-cell-db">设为默认地址</view>
								<switch color="#FDD100" @change="setDefaultAddr"  :checked="is_default" class="kaiguan" />
							</view>
					</view>
			</view>
		</view>
	<button class="confirm-btn" @click="addrId">确认
	</button>
	<!-- 省市区地址选择器组件 -->
	<cityPicker :addr_code="addr_code" :mask-close-able="maskCloseAble" @confirm="confirm"  @cancel="cancel" :visible="visible" />
<!-- <view class="">{{cityPicker}}</view> -->
	</view>
 </view>
</template>
<script>
import cityPicker from '../../components/piaoyi-cityPicker/pioayi-cityPicker.vue'
export default{
		data(){
			return{
				requt: 'https://4de16698-d9f4-443a-b416-ef1037cce952.bspapp.com/http',
				visible: false, //控制选择器显示和隐藏
				maskCloseAble: true, //点击模态框是否关闭弹框
				addr_text: '', //绑定地址
				addr_code: '', //初始地区编码（例:420102）
				name:'',
				tel:'',
				detail:'',    //收货地址详情
				is_default:false, //是否设为默认地址 true/false
				addr_id:'',   //地址ID
			}
		},
		onLoad() {
			// this.getAddrList()
		},
		components: {
		    cityPicker
		},
		methods:{
			// 保存收货地址信息接口
			addrId(){
				if((this.addr_text==''||this.name==''||this.tel==''||this.detail=='')){
					uni.$u.toast('请填写完整信息')
					return
				}
			let uid = uni.getStorageSync('uid');
			let token = uni.getStorageSync('token');
			uni.request({
				url: this.requt + '/order/saveAddress',
				method: 'POST',
				header:{
					token //自定义请求头信息
				},
				data:{
					name:this.name,
					tel:this.tel,
					addr_text:this.addr_text,
					addr_code:this.addr_code,
					detail:this.detail,
					is_default:this.is_default,
					uid,
					addr_id:''
				},
				success: res => {
					console.log(res);
					
				}
			});
			// 返回上一页并刷新
			let pages = getCurrentPages(); // 当前页面
			let beforePage = pages[pages.length - 2]; // 上一页
			uni.navigateBack({
			    success: function() {
			        beforePage.onLoad(); // 执行上一页的onLoad方法
			    }
			});
			},
			//省市区地址选择器插件
			open () {
			            this.visible = true
			        },
			confirm (val) {
			            // console.log(val)
			            this.addr_text = val.name
						this.addr_code=val.code
			            this.visible = false
			        },
			cancel () {
			            this.visible = false
			        },
			//默认地址事件		
			setDefaultAddr(e){
				this.is_default=e.detail.value
				console.log(e.detail.value);
				let uid = uni.getStorageSync('uid');
				let token = uni.getStorageSync('token');
				uni.request({
					url: this.requt + '/order/set_default_addr',
					method: 'POST',
					header:{
						token //自定义请求头信息
					},
					data:{
						uid,
						_id:this.addr_id
					},
					success: res => {
						console.log(res);
						
					}
				});
			},
	},
	}
</script>


<style lang="scss">
	.uni-input-placeholder {
		color: #999
	}
	.container {
		position: relative;
		width: 100vw;
		height: 90vh;
		overflow: hidden;
		background: #f7f7f7;
	}
	.input-content {
		background: #fff;
	}
	
	
	.input-item {
		position: relative;
		display: flex;
		flex-direction: row;
		align-items: center;
		height: auto;
		padding: 16upx 30upx;
		background: #fff;
		border-bottom: 1px solid #f5f5f7;
		&:last-child {
			margin-bottom: 0;
		}
		.pieckerInput{
			color: #333;
			width: calc(100% - 230upx);
			font-size: 30upx;
			display: inline-block;
			line-height: 60upx;
		}

		.xiangxi{
			width: 100%;
			height: 162upx;
			padding: 14upx 10upx;
			font-size: 30upx;
		}
		.tit {
			height: 60upx;
			line-height: 60upx;
			font-size: 30upx;
			color: $font-color-dark;
			width: 200upx
		}
		.iconfont {
			color: #999;
			line-height: 60upx;
			position: absolute;
			right: 30upx;
		}
		input {
			height: 60upx;
			font-size: $font-base + 2upx;
			color: $font-color-dark;
			flex: 1;
			width: calc(100% - 50upx);
			text-align: right;
		}
	
		.clear_input {
			position: absolute;
			right: 0;
			top: 10upx;
			padding: 10upx;
	
			.iconfont {
				font-size: 40upx;
				color: $font-color-light
			}
		}
	}
	
	.confirm-btn {
		position: fixed;
		left: 0;
		bottom: 0;
		width: 100%;
		height: 100upx;
		line-height: 100upx;
		border-radius: 4px;
		background: $color1;
		color: #fff;
		font-size: $font-lg;
		&:after {
			border-radius: 100px;
			border: none;
		}
	}
	.moren{
		border-top: 20upx solid #f7f7f7;
		padding: 0 30upx; 
		height: 110upx;
		line-height: 90upx;
		overflow: hidden;
		font-size: 30upx;
			.uni-list-cell-db{ 
				float: left;
				color: #333;
				}
		.kaiguan{
				float: right;
		} 
	}
	.allinfo {
		width: 100%;
		height: 100%;
		background: #fff;
	}

	.xzdz .box01 {
		width: 94%;
		height: 45px;
		border-bottom: 1px solid #f7f7f7;
		margin-left: 3%;
	}

	.xzdz .box01 input {
		width: 72%;
		height: 45px;
		float: right;
	}

	.xzdz .box01 text {
		width: 70px;
		line-height: 45px;

	}


	.xzdz .box01.mr .iconfont {
		line-height: 42px;
		font-size: 18px;
		vertical-align: middle;
	}

	.xzdz .box01.gouxuan .iconfont:before {
		color: #4499ee;
		content: "\e61e";
	}

	.allinfo .btn {
		width: 100%;
		height: 45px;
		line-height: 45px;
		background: #4499ee;
		border-radius: 0;
		position: fixed;
		bottom: 0;
		color: #fff;
		font-size: 16px;
	}

	.pickerMask {
		position: fixed;
		z-index: 1000;
		top: 0;
		right: 0;
		left: 0;
		bottom: 0;
		background: rgba(0, 0, 0, 0.6);
	}
uni-switch .wx-switch-input:not([class*="bg-"]), uni-switch .uni-switch-input:not([class*="bg-"]){
	
}
</style>
